﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Globalization;

namespace SinaWeiboApp_WP7.Utils
{
    public class DateConverter : IValueConverter
    {
        static CultureInfo cInfo = new CultureInfo("en-US");

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var dt = DateTime.ParseExact((string)value, "ddd MMM dd HH:mm:ss zzz yyyy", cInfo);
            var ts = DateTime.Now - dt;
            if (ts.Days > 0)
                return dt.ToString("MM月dd日 HH:mm");

            if (ts.Hours > 0)
                return ts.Hours.ToString() + "小时前";

            return ts.Minutes.ToString() + "分钟前";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
